package com.pocket.demo.core.mq.rabbitMQ;

import cn.hutool.json.JSONUtil;
import com.pocket.demo.business.controller.vo.UserRespVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.Message;

/**
 * @author cookie.
 **/
@Configuration
public class UserRegisterSuccessConsumer {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserRegisterSuccessConsumer.class);

    /**
     * 【demo-MQ-rabbitMQ-5.1】
     * <p> 被 @RabbitListener 标记的方法可以接受哪些参数？<br>
     * 处理源码位置 <br>
     *      {@link org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter#invokeHandler} <br>
     *      {@link org.springframework.messaging.handler.invocation.InvocableHandlerMethod#getMethodArgumentValues(Message, Object...)} <br>
     * 测试案例: <br>
     *      {@link com.pocket.demo.core.mq.rabbitMQ.demo.DirectConsumer} <br>
     */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange(name = RabbitMQConstant.EXCHANGE_USER, type = ExchangeTypes.TOPIC, durable = "true"), // 【demo-MQ-rabbitMQ-6.4】
            value = @Queue(name = RabbitMQConstant.QUEUE_USER_REGISTER_SUCCESS, durable = "true"), // 【demo-MQ-rabbitMQ-6.4】
            key = {RabbitMQConstant.ROUTING_KEY_USER_REGISTER_SUCCESS}
    ))
    //@RabbitListener(queues = RabbitMQConfig.QUEUE_USER_REGISTER_SUCCESS)
    public void userRegisterSuccess(UserRespVO userRespVO){
        LOGGER.debug("received user register success message : {}", JSONUtil.toJsonStr(userRespVO));
        // todo  mail to user
    }

}
